package chap1.version1;

import java.util.Map;

public class UtcTime extends TimeSubject {
    public int getUtcZeroTime() {
        return utcZeroTime;
    }

    public void setUtcZeroTime(int utcZeroTime) {
        this.utcZeroTime = utcZeroTime;
        notifyAllClocks();
    }

    private int utcZeroTime = 0;

    @Override
    public void notifyAllClocks() {
        for (Clock clock : super.clocks.values()) {
            clock.setLocalTimeFromUtcZeroTime(this.utcZeroTime);
        }
    }

    /**
     * 打印所有的时间
     */
    public void printTimeOfAllClocks() {
//        for (String clockName : super.clocks.keySet()) {
//            System.out.println(clockName + ": " + super.clocks.get(clockName).getTime());
//        }

        for (Map.Entry<String, Clock> stringClockEntry : super.clocks.entrySet()) {
            String clockName = stringClockEntry.getKey();
            Clock clock = stringClockEntry.getValue();
            System.out.println(clockName + ": " + clock.getTime());
        }
    }
}
